package org.wing.modules.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.wing.modules.product.entity.Product;
import org.wing.modules.product.mapper.ProductMapper;
import org.wing.modules.product.service.IProductService;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Override
    public Page<Product> pageList(Page<Product> page, String productName) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();

        if (productName != null && !productName.isEmpty()) {
            wrapper.like(Product::getProductName, productName);
        }

        wrapper.orderByDesc(Product::getCreateTime);
        return this.page(page, wrapper);
    }
}
